package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Rp_queryTool;
import hz.mobileproject.pda.ui.base.BaseCustomAdapter;

/**
 * Created by hasee on 2017/11/16.
 */

public class ToolsInventoryAdapter extends BaseCustomAdapter<Rp_queryTool,ToolsInventoryAdapter.ViewHolder> {

    public ToolsInventoryAdapter(Context mContext, List<Rp_queryTool> list) {
        super(mContext, list);
    }

    @Override
    protected int bindView() {
        return R.layout.tools_inventory_list_item;
    }

    @Override
    protected ViewHolder createViewHolder() {
        return new ViewHolder();
    }

    @Override
    protected void bindData(int position, View convertView, ViewHolder viewHolder) {
        if(position == 0){
            viewHolder.v_line.setVisibility(View.VISIBLE);
        }else{
            viewHolder.v_line.setVisibility(View.GONE);
        }
        Rp_queryTool tempData = mList.get(position);
        viewHolder.tv_toolsName.setText(tempData.getName());
        viewHolder.tv_toolsCode.setText(tempData.getAsset_code());
        viewHolder.tv_deptName.setText(tempData.getDept_name());
        if(tempData.getCheckState() == Rp_queryTool.STATE_FINISH){
            if(tempData.getFinishType() == Rp_queryTool.FINISHTYPE_ERR){
                viewHolder.tv_checkState.setText("已完成（异常）");
                viewHolder.tv_checkState.setTextColor(ContextCompat.getColor(mContext,R.color.orangered));
            }else{
                viewHolder.tv_checkState.setText("已完成");
                viewHolder.tv_checkState.setTextColor(ContextCompat.getColor(mContext,R.color.green));
            }
        }else{
            viewHolder.tv_checkState.setText("未完成");
            viewHolder.tv_checkState.setTextColor(ContextCompat.getColor(mContext,R.color.orangered));
        }
    }

    class ViewHolder{
        @ViewInject(R.id.tv_name_tools)
        TextView tv_toolsName;
        @ViewInject(R.id.tv_code_tools)
        TextView tv_toolsCode;
        @ViewInject(R.id.tv_state_tools)
        TextView tv_checkState;
        @ViewInject(R.id.tv_dept_name)
        TextView tv_deptName;
        @ViewInject(R.id.v_line)
        View v_line;
    }

}
